home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / t_sys5 / unixcpio.gz / unixnet.cpio / lcsum.c < prev    next >
C/C++ Source or Header  |  1994-07-11  |  763b  |  29 lines

  1. #include "global.h"
  2. #if    (defined(MPU8086) || defined(MPU8080) || defined(vax) || defined(iAPX286))
  3. #define    LITTLE_ENDIAN    /* Low order bytes are first in memory */
  4. #endif            /* Almost all other machines are big-endian */
  5. /*
  6.  * Word aligned linear buffer checksum routine.  Called from mbuf checksum
  7.  * routine with simple args.  Intent is that this routine may be replaced
  8.  * by assembly language routine for speed if so desired.
  9.  */
  10. int16
  11. lcsum(wp,len)
  12. register int16 *wp;
  13. register int16 len;
  14. {
  15.     int16 eac();
  16.     register int32 sum = 0;
  17.     int16 result;
  18.  
  19.     while(len-- != 0)
  20.         sum += *wp++;
  21.     result = eac(sum);
  22. #ifdef    LITTLE_ENDIAN
  23.     /* Swap the result because of the (char *) to (int *) type punning */
  24.     result = (result << 8) | (result >> 8);
  25. #endif
  26.     return result;
  27. }
  28.  
  29.